package cn.wind.xboot.logic.cli.service.impl;

import cn.wind.xboot.logic.cli.dao.CliClientMapper;
import cn.wind.xboot.logic.cli.dto.CliDto;
import cn.wind.xboot.logic.cli.entity.CliClient;
import cn.wind.xboot.logic.cli.service.ICliClientService;
import cn.wind.xboot.logic.cli.service.ICliInfoService;
import cn.wind.xboot.logic.dto.CliStoreDto;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 平台会员表 服务实现类
 * </p>
 *
 * @author xukk
 * @since 2018-06-19
 */
@Service
@Transactional
public class CliClientServiceImpl extends ServiceImpl<CliClientMapper, CliClient> implements ICliClientService {
    @Autowired
    private ICliInfoService cliInfoService;
    @Override
    public boolean updateForAccountNonLocked(Boolean accountNonLocked, String username) {
        CliClient cliClient=new CliClient();
        cliClient.setAccountNonLocked(accountNonLocked);
        return update(cliClient,new QueryWrapper<CliClient>().lambda().eq(CliClient::getUsername,username));
    }

    @Override
    public CliClient findByUsername(String username) {
        return this.baseMapper.findByUsername(username);
    }


    @Override
    public boolean saveEntity(CliClient cliClient) {
        save(cliClient);
        if(cliClient.getCliInfo()!=null){
            cliClient.getCliInfo().setCliId(cliClient.getId());
            cliInfoService.save(cliClient.getCliInfo());
        }
        return true;
    }

    @Override
    public boolean updatePassword(Long id, String password) {
        CliClient cliClient=new CliClient();
        cliClient.setPassword(password);
        return update(cliClient,new QueryWrapper<CliClient>().lambda().eq(CliClient::getId,id));
    }

    @Override
    public CliClient findCliInfo(Long id) {
        CliClient cliClient=getById(id);
        if(cliClient==null)
        {
            return null;
        }
        cliClient.setCliInfo(cliInfoService.selectByCliId(id));
        return cliClient;
    }

    @Override
    public IPage<CliClient> findByCondition(IPage page, Map<String, Object> var1) {
        return this.baseMapper.findByCondition(page,var1);
    }

    @Override
    public CliStoreDto findById(Long id) {
        return this.baseMapper.findById(id);
    }

    @Override
    public List<CliDto> findCliAll() {
        return this.baseMapper.findCliAll();
    }

    @Override
    public CliClient findCliById(Long cliId) {
        return this.baseMapper.findCliById(cliId);
    }


}
